// 编写一个函数来查找字符串数组中的最长公共前缀。

// 如果不存在公共前缀，返回空字符串 ""。

int check(char ** strs, int idx, int strsSize) {
    char ref = strs[0][idx];
    int count = 1;
    for (int i = 1; i < strsSize; i++) {
        if (ref == strs[i][idx]) count++;
    }
    return (count == strsSize);
}

char * longestCommonPrefix(char ** strs, int strsSize){
    if (strsSize == 0) return "";
    // 先找出最小的长度，方便后面的统计工作
    int cnt = 0, lens[strsSize], minlen = INT_MAX;
    for (int i = 0; i < strsSize; i++) {
        minlen = fmin(minlen, strlen(strs[i]));
    }

    for (int i = 0; i < minlen; i++) {
        if( check(strs, i, strsSize) ) cnt++;
        else break;
    }
    if (cnt == 0) return "";

    char *res = malloc(sizeof(char) * (cnt+1));
    for (int i = 0; i < cnt; i++) {
        res[i] = strs[0][i];
    }
    res[cnt] = '\0';
    return res;
}